//
//  AudioPublishTextViewBottom.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/11/14.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "AudioPublishTextViewBottom.h"

@implementation AudioPublishTextViewBottom
+(instancetype)initWithaddView:(UIView *)faterView AndAboveView:(UIView *)aboveView AndTitle:(NSString *)title AndPlaceholder:(NSString *)placeHolder AndArticalLength:(NSString *)lenth AndViewHeight:(CGFloat)height AndShowMustToStar:(BOOL)showStar{
    AudioPublishTextViewBottom *view = [[AudioPublishTextViewBottom alloc] init];
    [faterView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(faterView);
        make.height.mas_equalTo(height);
        make.top.equalTo(aboveView.mas_bottom);
    }];
    UILabel *titleLabel = [[UILabel alloc] init];
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:title];
    titleLabel.attributedText = attri;
    titleLabel.font = [UIFont systemFontOfSize:14];
    titleLabel.textColor = COLOR_HEX(0x121212);
    if (showStar) {
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",@"*",title]];
        [view attaributestrMakeDesign:attri];
        titleLabel.attributedText = attri;
    }
    [view addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view.mas_left).offset(scaleLeftAndRight(10));
        make.top.equalTo(view.mas_top).offset(scaleTopAndBottom(7));
        make.height.mas_equalTo(scaleTopAndBottom(30));
        make.right.equalTo(view.mas_right);
    }];
    view.descriptextVeiw = [[UITextView alloc] init];
    [view addSubview:view.descriptextVeiw];
    [view.descriptextVeiw mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view.mas_left).offset(scaleLeftAndRight(10));
        make.top.equalTo(titleLabel.mas_bottom).offset(scaleTopAndBottom(10));
        make.bottom.equalTo(view.mas_bottom);
        make.right.equalTo(view.mas_right).offset(scaleLeftAndRight(-10));
        
    }];
    view.placeHolder = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, scaleLeftAndRight(150), scaleTopAndBottom(15))];
    view.placeHolder.font = [UIFont systemFontOfSize:14];
    view.placeHolder.text = placeHolder;
    view.placeHolder.textColor = COLOR_HEX(0xC0C0C0);
    [view.descriptextVeiw addSubview:view.placeHolder];
    view.stirngLenghLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    view.stirngLenghLabel.textColor = COLOR_HEX(0xADADAD);
    view.stirngLenghLabel.textAlignment = NSTextAlignmentRight;
    view.stirngLenghLabel.text = lenth;
    view.stirngLenghLabel.font = [UIFont systemFontOfSize:10];
    [view addSubview:view.stirngLenghLabel];
    [view.stirngLenghLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(view.descriptextVeiw.mas_right);
        make.bottom.equalTo(view.descriptextVeiw.mas_bottom);
        make.width.mas_equalTo(scaleLeftAndRight(100));
        make.height.mas_equalTo(scaleTopAndBottom(15));
    }];
    
    
    return view;
}

-(void)attaributestrMakeDesign:(NSMutableAttributedString *)attri{
    [attri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 1)];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
